<template>
  <div>
    <van-nav-bar
      :title="title"
      fixed
      class="page-header"
      @click-left="showMenu = !showMenu"
    >
      <template slot="left">
        <van-icon name="wap-nav" size="18" v-if="left==='nav'"/>
        <van-icon name="arrow-left" size="18" v-if="left==='back'" @click="$router.back()"/>
      </template>
      <template slot="right">
        <slot />
      </template>
    </van-nav-bar>
    <van-popup v-model="showMenu" position="top" class="menu-popup" :overlay-style="{zIndex: 8}" duration="0.2" close-on-click-overlay>
      <div class="menu-content">
        <div
          v-for="item in menuItems"
          :key="item.name"
          class="menu-item"
          @click="onMenuClick(item)"
        >
          {{ item.name }}
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
export default {
  name: "PageHeader",
  props: {
    title: {
      type: String,
      default: "",
    },
    left: {
      type: String,
      default: "nav",
    },
  },
  data() {
    return {
      showMenu: false,
      menuItems: [
        { name: "订单管理", path: "/order" },
        { name: "用户评价", path: "/" },
        { name: "订单行程", path: "/orderTrip" },
        { name: "预警信息", path: "/alerts" },
        { name: "售后管理", path: "/after-sales" },
      ],
    };
  },
  methods: {
    onMenuClick(item) {
      this.showMenu = false;
      setTimeout(() => {
        this.$router.push(item.path + `?v=${+new Date()}`)
      }, 300)
    },
  },
};
</script>

<style lang="scss" scoped>
.page-header {
  background-color: #393649;
  z-index: 10;
  /deep/ .van-nav-bar__title,
  /deep/ .van-icon {
    color: white;
  }
}
/deep/ .menu-popup{
  z-index: 9!important;
  margin-top:46px;
}
/deep/ .menu-popup.van-popup--top {
  height: auto;
}

.menu-content {
  padding: 16px;
  background-color: #393649;
  color: white;
  text-align: center;

  .menu-item {
    padding: 12px 0;
    font-size: 16px;
    cursor: pointer;
    &:not(:last-child) {
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
  }
}
</style> 
